package com.zkw.group.controller;

import com.alibaba.fastjson.JSON;
import com.zkw.group.entity.ProfesTerm;
import com.zkw.group.entity.ProfesTermCourse;
import com.zkw.group.entity.QueryInfo;
import com.zkw.group.service.PublicProfesTermService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@Api(description = "公众查看学期以及有关信息")
@CrossOrigin
@RestController
@RequestMapping("/Publics")
public class PublicProfesTermController {

    @Autowired
    private PublicProfesTermService publicProfesTermService;

    @ApiOperation(value = "分页查询学期列表")
    @GetMapping("/AllProfesTerm")
    public String getAllProfesTermList(QueryInfo queryInfo) {
        int numbers = publicProfesTermService.getProfesTermCounts(queryInfo.getQuery());
        int pageStart = (queryInfo.getPageNum()-1)*queryInfo.getPageSize();
        List<ProfesTerm> profesTerms = publicProfesTermService.getAllProfesTermList(queryInfo.getQuery(),pageStart,queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers",numbers);
        res.put("data", profesTerms);
        return JSON.toJSONString(res);
    }

    @ApiOperation(value = "分页查询学期内课程列表")
    @GetMapping("/AllProfesTermCourse")
    public String getAllProfesTermCourseList(QueryInfo queryInfo) {
        int numbers = publicProfesTermService.getProfesTermCourseCounts(queryInfo.getQuery(),queryInfo.getRole());
        int pageStart = (queryInfo.getPageNum()-1)*queryInfo.getPageSize();
        List<ProfesTermCourse> profesTermCourses = publicProfesTermService.getAllProfesTermCourseList(queryInfo.getQuery(),queryInfo.getRole(),pageStart,queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers",numbers);
        res.put("data",profesTermCourses);
        return JSON.toJSONString(res);
    }
}
